package com.five.mobile.customer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Component
@Slf4j
public class MessageReceiver {
    @RabbitListener(queues = "banner")
    public void receiveMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        log.info("开始处理banner队列的数据");
        log.info("接收到的消息是：{}", message);
        log.info("处理开始");
        log.info("处理结束，进行手动确认");
        //手动确认
        channel.basicAck(deliveryTag, false);
    }

    @RabbitListener(queues = "order")
    public void receiveOrderMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        log.info("开始处理order队列的数据");
        log.info("接收到的消息是：{}", message);
        log.info("处理开始");
        log.info("处理结束，进行手动确认");
        // 手动确认
        channel.basicAck(deliveryTag, false);
    }
}
